View Javadoc
1 /* 2 * Angkor Web Framework 3 * 4 * Distributable under LGPL license. 5 * See terms of license at gnu.org. 6 */ 7 8 package com.tirsen.angkor.table; 9 10 import com.tirsen.angkor.widget.BasicValueModel; 11 import com.tirsen.angkor.widget.ValueModel; 12 13 import java.util.Arrays; 14 import java.util.LinkedList; 15 import java.util.List; 16 17 /*** 18 * @author $Author: tirsen $ 19 * @version $Revision: 1.5 $ 20 * <BR> 21 * $Id: DefaultTableModel.java,v 1.5 2002/10/09 21:37:37 tirsen Exp $ 22 */ 23 public class DefaultTableModel extends AbstractTableModel 24 { 25 /*** 26 * The <code>List</code> of <code>List</code>s of <code>Object</code> values. 27 */ 28 private List dataList = new LinkedList(); 29 30 /*** 31 * The <code>List</code> of <code>Object</code> column names. 32 */ 33 private List columnNames = new LinkedList(); 34 35 public void addColumn(String name) 36 { 37 columnNames.add(name); 38 signalChanged(); 39 } 40 41 /*** 42 * Adds a row to the end of this table. 43 */ 44 public void addRow(Object[] columnValues) 45 { 46 dataList.add(Arrays.asList(columnValues)); 47 signalChanged(); 48 } 49 50 public void setRow(int row, Object[] columnValues) 51 { 52 int size = dataList.size(); 53 for (int i = size - row; i < size + 1; i++) 54 { 55 dataList.add(null); 56 } 57 dataList.set(row, Arrays.asList(columnValues)); 58 signalChanged(); 59 } 60 61 public String getColumnName(int column) 62 { 63 Object name = columnNames.get(column); 64 return name != null ? name.toString() : ""; 65 } 66 67 public ValueModel getValueAt(final int row, final int column) 68 { 69 return new BasicValueModel() 70 { 71 public Object getValue() 72 { 73 return ((List) dataList.get(row)).get(column); 74 } 75 76 public void setValue(Object value) 77 { 78 ((List) dataList.get(row)).set(column, value); 79 } 80 }; 81 } 82 83 public int getColumnCount() 84 { 85 return columnNames.size(); 86 } 87 88 public int getRowCount() 89 { 90 return super.getRowCount() == -1 ? dataList.size() : super.getRowCount(); 91 } 92 93 public void empty() 94 { 95 super.empty(); 96 dataList.removeAll(dataList); 97 signalChanged(); 98 } 99 }

This page was automatically generated by Maven